package org.libermundi.theorcs.main.tapestry.pages;

import javax.inject.Inject;

import org.apache.tapestry5.alerts.AlertManager;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.services.Request;
import org.libermundi.theorcs.main.tapestry.base.MainPublicPage;

import com.google.common.base.Strings;

/**
 * Login page of application TheORCS.
 */
public class Login extends MainPublicPage {
	public static final String PAGE_ID="main.pages.login";
	
	@Inject
	private Request _request;
	
	@Inject
	private AlertManager _alertManager;
	
	@Inject
	private Messages _messages;
	
	@Property(write=false)
	private String _originalUrl;
	
	/* (non-Javadoc)
	 * @see org.libermundi.theorcs.core.tapestry.base.BasePage#getPageId()
	 */
	@Override
	public String getPageId() {
		return PAGE_ID;
	}
	
	public void onActivate(String originalUrl){
		_originalUrl = originalUrl;
	}
	
	@SetupRender
	public void setupRender(){
		if(!Strings.isNullOrEmpty(_request.getParameter("failed"))){
			_alertManager.error(_messages.get("main.login.failure"));
		}
	}
	
}
